<!--{include admin_header}-->
                <div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>
<!--{include admin_breadcrumb}-->
					</div>

					<div class="page-content">
						<div class="page-header">
							<h1>{$_G['admincp']['actname']}<small><i class="icon-double-angle-right"></i>{$_G['admincp']['optname']}</small></h1>
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
								<!-- PAGE CONTENT BEGINS -->

								<div class="row-fluid">
									<div class="span12">
										<div class="widget-box">
											<div class="widget-header widget-header-blue widget-header-flat">
												<h4 class="lighter">新客户</h4>
											</div>

											<div class="widget-body">
												<div class="widget-main">
													<div id="fuelux-wizard" class="row-fluid" data-target="#step-container">
														<ul class="wizard-steps">
															<li data-target="#step1" class="active">
																<span class="step">1</span>
																<span class="title">客户信息</span>
															</li>
															<li data-target="#step2">
																<span class="step">2</span>
																<span class="title">授权验证</span>
															</li>
														</ul>
													</div>

													<hr />
													<div class="step-content row-fluid position-relative" id="step-container">
													<form class="form-horizontal" action="?action=customer&operation=edit&id={$customer['id']}" id="validation-form" method="post">
                                                    	<input name="id" value="{$customer['id']}" type="hidden" />
														<div class="step-pane active" id="step1">
																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="email">公司名称:</label>

																	<div class="col-xs-12 col-sm-3">
																		<div class="clearfix input-icon input-icon-right">
																			<input type="text" name="name" id="name" value="{$customer['name']}" class="col-xs-12 col-sm-12" />
                                                                            <i class="icon-spinner icon-spin check-loading hide blue"></i>
																		</div>
																	</div>
																</div>
																<div class="form-group customers-list hide">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right"></label>
																	<div class="col-xs-12 col-sm-3">
                                                                        <table class="table table-striped table-bordered table-hover">
                                                                            <thead class="thin-border-bottom">
                                                                                <tr>
                                                                                    <th><i class="icon-user"></i>客户名称</th>
                                                                                    <th class="hidden-480">业务员</th>
                                                                                </tr>
                                                                            </thead>
                                                                            <tbody></tbody>
                                                                        </table>
																	</div>
																</div>


																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="state">公司性质</label>

																	<div class="col-xs-12 col-sm-9">
																		<select id="nature" name="nature" class="select2" data-placeholder="选择...">${option($natures, $customer['nature'], '选择')}</select>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right">客户状态</label>

																	<div class="col-xs-12 col-sm-9">
																		<div>
<!--{loop $status $k $v}-->
																			<label class="blue">
																				<input name="status" value="{$k}" ${$customer['status'] == $k ? 'checked' : ''} type="radio" class="ace" />
																				<span class="lbl"> {$v}</span>
																			</label>
<!--{/loop}-->
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right">需求意向</label>

																	<div class="col-xs-12 col-sm-9">
																		<div class="col-sm-7">
<!--{loop $demands $k $v}-->
																			<label class="blue">
																				<input name="demand[{$k}]" value="1" ${$customer['demands'][$k] ? 'checked' : ''} type="checkbox" class="ace" />
																				<span class="lbl"> {$v}</span>
																			</label>
<!--{/loop}-->
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="url">客户网站:</label>

																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<input type="text" id="url" name="url" value="{$customer['url']}" class="col-xs-12 col-sm-5" />
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right">客户地域</label>
																	<div class="col-xs-12 col-sm-9">
																		<select id="province" name="province" class="select2 select-100" data-placeholder="选择...">${option($provinces, $customer['province'], '选择省份')}</select>
																		<select id="city" name="city" class="select2 select-100" data-placeholder="选择...">${option($citys, $customer['city'], '选择城市')}</select>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="url">客户地址:</label>

																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<input type="text" id="address" name="address" value="{$customer['address']}" class="col-xs-12 col-sm-5" />
																		</div>
																	</div>
																</div>

																<div class="hr hr-dotted"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="contact_name">首要联系人姓名:</label>

																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<input type="text" id="contact_name" name="contact_name" value="{$customer['contact_name']}" class="col-xs-12 col-sm-5" />
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="contact_job">职位:</label>

																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																		<select id="contact_job" name="contact_job" class="select2" data-placeholder="选择...">${option($jobs, $customer['contact_job'], '选择')}</select>
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="contact_tel">固定电话:</label>

																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<input type="text" id="contact_tel" name="contact_tel" value="{$customer['contact_tel']}" class="col-xs-12 col-sm-5" />
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="contact_phone">手机:</label>

																	<div class="col-xs-12 col-sm-9">
																		<div class="input-group">
																			<span class="input-group-addon">
																				<i class="icon-phone"></i>
																			</span>

																			<input type="tel" id="contact_phone" value="{$customer['contact_phone']}" name="contact_phone" />
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="contact_email">邮箱:</label>

																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<input type="text" id="contact_email" name="contact_email" value="{$customer['contact_email']}" class="col-xs-12 col-sm-5" />
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="contact_qq">QQ:</label>

																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<input type="text" id="contact_qq" name="contact_qq" value="{$customer['contact_qq']}" class="col-xs-12 col-sm-5" />
																		</div>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="contact_qq">下次沟通日期:</label>

																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<input name="next_contact_time" type="text" value="${$customer['next_contact_time'] ? date('Y-m-d H:i:s', $customer['next_contact_time']) : ''}" class="col-xs-12 col-sm-5 date-picker" data-date-format="yyyy-mm-dd">
																		</div>
																	</div>
																</div>

																<div class="hr hr-dotted"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="state">客户来源</label>
																	<div class="col-xs-12 col-sm-9">
																		<select id="source" name="source" class="select2" data-placeholder="选择...">${option($sources, $customer['source'], '选择')}</select>
																	</div>
																</div>

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="state">销售人员</label>
																	<div class="col-xs-12 col-sm-9">
																		<select id="adminid" name="adminid" class="select2" ${!$admincp->manage ? 'disabled="disabled"' : ''} data-placeholder="选择...">
                                                                        ${option($admins, $customer['adminid'], '客户池')}
																		</select>
																	</div>
																</div>

																<!-- <div class="form-group" id="partner">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="contact_qq">合伙人账号:</label>
																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<input type="text" id="account" name="account" value="{$customer['account']}" class="col-xs-12 col-sm-5" />
																		</div>
																	</div>
																</div>
																<input type="hidden" name="remark" value="{$customer['remark']}">
																<div class="form-group" id="partner">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="state">合伙人密码:</label>
																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<input type="text" id="pass" name="pass" value="{$customer['pass']}" class="col-xs-12 col-sm-5" />
																		</div>
																	</div>
																</div> -->

																<div class="space-2"></div>

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="url">客户备注:</label>

																	<div class="col-xs-12 col-sm-9">
                                                                        <div class="widget-box col-sm-6">
                                                                            <div class="widget-header widget-header-small header-color-blue">  </div>
                                
                                                                            <div class="widget-body">
                                                                                <div class="widget-main no-padding">
                                                                                    <textarea class="span12" name="detail" data-provide="markdown" rows="10">{$customer['detail']}</textarea>
                                                                                </div>
                                                                            </div>
                                                                        </div>
																	</div>
																</div>

														</div>

														<div class="step-pane" id="step2">
<!--{include admin_uac}-->
														</div>
														</form>
													</div>

													<hr />
													<div class="row-fluid wizard-actions">
														<button class="btn btn-prev"><i class="icon-arrow-left"></i>上一步</button>
														<button class="btn btn-success btn-next" data-last="完成">下一步<i class="icon-arrow-right icon-on-right"></i></button>
													</div>
												</div><!-- /widget-main -->
											</div><!-- /widget-body -->
										</div>
									</div>
								</div>
								<!-- PAGE CONTENT ENDS -->
							</div><!-- /.col -->
						</div><!-- /.row -->
					</div><!-- /.page-content -->
				</div>
<!--{include admin_footer}-->
		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="/static/ace/assets/css/jquery-ui-1.10.3.custom.min.css" />
		<link rel="stylesheet" href="/static/ace/assets/css/select2.css" />
		<link rel="stylesheet" href="/static/ace/assets/css/datepicker.css" />
		<!-- page specific plugin scripts -->

		<script type="text/template" id="customer-template">
                                                                                <tr>
                                                                                    <td class="">{name}</td>
                                                                                    <td class="hidden-480">{admin}</td>
                                                                                </tr>
        </script>

		<script src="/static/ace/assets/js/date-time/bootstrap-datepicker.min.js"></script>
		<script src="/static/ace/assets/js/markdown/markdown.min.js"></script>
		<script src="/static/ace/assets/js/markdown/bootstrap-markdown.min.js"></script>

		<script src="/static/ace/assets/js/fuelux/fuelux.wizard.min.js"></script>
		<script src="/static/ace/assets/js/jquery.validate.min.js"></script>
		<script src="/static/ace/assets/js/additional-methods.min.js"></script>
		<script src="/static/ace/assets/js/jquery.maskedinput.min.js"></script>
		<script src="/static/ace/assets/js/select2.min.js"></script>
		<script type="text/javascript">
			D.Main = {
				init : function(){
					$('#province').change(function(){
						var pid = $(this).val();
						var html = '<option value="0">选择城市</option>';
						if( pid ){
							$('#city').html(html + '<option disabled>数据加载中</option>').select2({allowClear:true});
							D.ajax.get('?action=customer&operation=edit&act=public_get_city&dataid=' + pid, function(json){
								if ( json.data ){
									$.each(json.data, function(i, n){
										if ( n.id && n.name ){
											html += '<option value="'+n.id+'">'+n.name+'</option>';
										}
									});
								}
								$('#city').html(html).select2({allowClear:true});
							});
						}else{
							$('#city').html(html).select2({allowClear:true});
						}
					});
<!--{if !$customer}-->
					$('#name').on('blur', function(){
						var box = $(this);
						var last = $(this).attr('last');
						var name = box.val();
						box.attr('last', name);
						if( name && last != name ){
							$('.check-loading').removeClass('hide');
							box.attr('readonly', true);
	
							D.ajax.get('?action=customer&operation=edit&act=search&name=' + name, function(json){
								var html = '';
								if( !json.error || json.type == 'data' ){
									if( json.data && json.data.customers ){
										$.each(json.data.customers, function(i, n){
											var user = json.data.admins[n.adminid];
											if( user ){
												var company = json.data.companys[user.companyid];
												if( company ){
													var data = {
														name : n.name,
														admin : '[' + company.name + '] ' + (user.realname ? user.realname : user.username)
													};
													html += D.T.selector('#customer-template', data);
												}
											}
										});
									}
								}
								if( !html ){
									$('.customers-list').addClass('hide');
								}else{
									$('.customers-list').removeClass('hide').hide().slideDown();
									$('.customers-list .table tbody').html(html);
								}
								box.removeAttr('readonly');
								$('.check-loading').addClass('hide');
							});
						}
						if( !name ){
							$('.customers-list').addClass('hide');
						}
					});
<!--{/if}-->
				}
			}
			jQuery(function($) {
				$('.date-picker').datepicker({autoclose:true}).next().on(ace.click_event, function(){
					$(this).prev().focus();
				});
				$('[data-rel=tooltip]').tooltip();

				$(".select2").css('width','200px').select2({allowClear:true}).on('change', function(){
					$(this).closest('form').validate().element($(this));
				}); 
				$('.select-100').css('width', 100);

				var $validation = true;
				$('#fuelux-wizard').ace_wizard().on('change' , function(e, info){
					if(info.step == 1 && $validation) {
						if(!$('#validation-form').valid()) return false;
					}
				}).on('finished', function(e) {
					var data = $('#validation-form').serialize();
					var loading = bootbox.dialog({
						message: '<div class="tree-loading" style="text-align: center;"><i class="icon-refresh icon-spin blue"></i></div>' 
					});
					D.ajax.postdata($('#validation-form').attr('action'), data, function(json){
						bootbox.hideAll();
						var buttons = json.error ? {
							danger : {
								label : "错误",
								className : "btn-sm btn-primary"
							}
						} : {
							success : {
								label : "OK",
								className : "btn-sm btn-primary",
								callback : function(){
									if( json.opt ){
										window.location.href = 'index.php?action=customer&operation=edit&detail=yes&id=' + json.opt;
									}else{
										window.location.reload();
									}
								}
							}
						};
						bootbox.dialog({
							message: json.data, 
							buttons: buttons
						});
					});
				}).on('stepclick', function(e){
					//return false;//prevent clicking on steps
				});

				//documentation : http://docs.jquery.com/Plugins/Validation/validate
			
				$.mask.definitions['~']='[+-]';
				$('#contact_phone').mask('99999999999');
			
				jQuery.validator.addMethod("phone", function (value, element) {
					return this.optional(element) || /^1[3458][\d]{9}$/.test(value);
				}, "请输入一个有效的手机号码.");
			
				$('#validation-form').validate({
					debug : true,
					errorElement: 'div',
					errorClass: 'help-block',
					focusInvalid: false,
					rules: {
						contact_email : {
							required: false,
							email : true
						},
						password: {
							required: true,
							minlength: 5
						},
						password2: {
							required: true,
							minlength: 5,
							equalTo: "#password"
						},
						province : {
							required : false
						},
						name: {
							required: true
						},
						contact_phone: {
							required: false,
							phone : 'required'
						},
						url: {
							required: false,
							url: true
						},
						comment: {
							required: true
						},
						status : {
							required : true
						},
						demand : {
							required: true
						},
						platform: {
							required: true
						},
						subscription: {
							required: true
						},
						gender: 'required',
						agree: 'required'
					},
			
					messages: {
						status : {
							required: "请选择一个状态"
						},
						contact_email : {
							email : '请输入一个正确的Email地址'
						},
						demand : {
							required : '请选择客户需求意向'
						},
						name : {
							required: "请输入公司名称"
						},
						password: {
							required: "Please specify a password.",
							minlength: "Please specify a secure password."
						},
						subscription: "Please choose at least one option",
						gender: "Please choose gender",
						agree: "Please accept our policy"
					},
			
					invalidHandler: function (event, validator) { //display error alert on form submit   
						$('.alert-danger', $('.login-form')).show();
					},
			
					highlight: function (e) {
						$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
					},
			
					success: function (e) {
						$(e).closest('.form-group').removeClass('has-error').addClass('has-info');
						$(e).remove();
					},
			
					errorPlacement: function (error, element) {
						if(element.is(':checkbox') || element.is(':radio')) {
							var controls = element.closest('div[class*="col-"]');
							if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
							else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
						}
						else if(element.is('.select2')) {
							error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
						}
						else if(element.is('.chosen-select')) {
							error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
						}
						else error.insertAfter(element.parent());
					},
			
					submitHandler: function (form) {
					},
					invalidHandler: function (form) {
					}
				});
			
				$('#modal-wizard .modal-header').ace_wizard();
				$('#modal-wizard .wizard-actions .btn[data-dismiss=modal]').removeAttr('disabled');
			});
		</script>
</body>
</html>
